package  com.bs.medicine.struts.action;

import java.io.PrintWriter;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.bs.entity.MedicineIn;
import com.bs.entity.MedicineInfo;
import com.bs.entity.MedicineOut;
import com.google.gson.Gson;
import com.opensymphony.xwork2.ActionSupport;

public class MedicineStorageAction extends ActionSupport {
	//药品列表信息
	private List medicineinfo;
//	private MedicineInfoService medicineService;
	private String searchId;
	private List<String> codelist;
//	private MedicineStorageService storageService;
	private String code;
//	private MedicineStorage  medicineStorage;
	private String medicineId;
	private MedicineIn  medicineIn;
	private MedicineOut medicineOut;
	
	//药品入库出库列表
	private List list;

	public List getList() {
		return list;
	}

	public void setList(List list) {
		this.list = list;
	}

	public MedicineOut getMedicineOut() {
		return medicineOut;
	}

	public void setMedicineOut(MedicineOut medicineOut) {
		this.medicineOut = medicineOut;
	}

	public MedicineIn getMedicineIn() {
		return medicineIn;
	}

	public void setMedicineIn(MedicineIn medicineIn) {
		this.medicineIn = medicineIn;
	}

	public String getMedicineId() {
		return medicineId;
	}

	public void setMedicineId(String medicineId) {
		this.medicineId = medicineId;
	}

	

	public String getSearchId() {
		return searchId;
	}

	public void setSearchId(String searchId) {
		this.searchId = searchId;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	

	public List<String> getCodelist() {
		return codelist;
	}

	public void setCodelist(List<String> codelist) {
		this.codelist = codelist;
	}

	public String getSearchName() {
		return searchId;
	}

	public void setSearchName(String searchName) {
		this.searchId = searchName;
	}

	

	public List getMedicineinfo() {
		return medicineinfo;
	}

	public void setMedicineinfo(List medicineinfo) {
		this.medicineinfo = medicineinfo;
	}

	/**
	 * 进入入库登记界面
	 * 
	 * @return
	 * @throws Exception
	 */
	public String registerMedicineIn() throws Exception {
//		medicineinfo = medicineService.getAllMedicineList();
		return SUCCESS;
	}

	/**
	 * 进入出库登记界面
	 * 
	 * @return
	 * @throws Exception
	 */
	public String registerMedicineOut() throws Exception {
	//	medicineinfo = medicineService.getAllMedicineList();
		return SUCCESS;
	}

	/**
	 * 根据药品名搜索出所有匹配的药品编码
	 * 
	 * @return
	 * @throws Exception
	 */
	public String searchCode() throws Exception {
	 //   code =storageService.getMedicineCode(searchId);
		HttpServletResponse response = ServletActionContext.getResponse();
		response.setHeader("pragma", "no-cache");
		response.setHeader("cache-control", "no-cache");
		response.setContentType("application/json ;charset=utf-8");
		PrintWriter out = response.getWriter();
		
		//返回结果封装成gson形式
		Gson gson = new Gson();
		String result = gson.toJson(code);
		out.println(result);
		out.flush();
        out.close();
		return null;
	}
	/**
	 * 药品入库登记
	 * @return
	 * @throws Exception
	 */
	public String saveIn() throws Exception{
		
	//	MedicineInfo  meinfo =medicineService.getMedicineInfoById(medicineId);
	//    medicineIn.setMedicineInfo(meinfo);
	 //   storageService.saveMedicineIn(medicineIn);
		return SUCCESS;
	}
	/**
	 * 药品出库登记
	 * @return
	 * @throws Exception
	 */
	public  String saveOut() throws Exception{
	//	MedicineInfo  meinfo =medicineService.getMedicineInfoById(medicineId);
	//    medicineOut.setMedicineInfo(meinfo);
	 //   storageService.saveMedicineOut(medicineOut);
		return SUCCESS;
	}
	/**
	 * 药品入库记录
	 * @return
	 * @throws Exception
	 */
	public String showMedicineIn() throws Exception{
	//	list =storageService.getMedicineInList();
		return SUCCESS;
	}
	/**
	 * 药品出库记录
	 * @return
	 * @throws Exception
	 */
	public String showMedicineOut() throws Exception{
	//	list=storageService.getMedicineOutList();
		return SUCCESS;
	}
	/**
	 * 编辑保存
	 * @return
	 * @throws Exception
	 */
	public String editSaveMedicineIn() throws Exception{
		HttpServletRequest request =ServletActionContext.getRequest();
		String incount =request.getParameter("inCount");
		String inId =request.getParameter("inId");
	//	medicineIn =storageService.queryMedicineIn(inId);
	//	medicineIn.setInCount(Long.parseLong(incount));
	//    storageService.editMedicineIn(medicineIn);
		return SUCCESS;
	}
	
	
    
   /**
    * 查询入库信息
    * @return
    * @throws Exception
    */
    public String queryMedicineIn() throws Exception{
   // 	medicineIn =storageService.queryMedicineIn(searchId);
    	return SUCCESS;
    }
    
    /**
     * 查询出库信息
     * @return
     * @throws Exception
     */
    public String queryMedicineOut() throws Exception{
    	return SUCCESS;
    }
}
